home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.mactech.com 2010
/
ftp.mactech.com.tar
/
ftp.mactech.com
/
util
/
EvenBetterBusError.sit
/
EvenBetterBusError
/
EvenBetterBusError (Boyd)
next >
Wrap
Text File
|
1994-10-12
|
6KB
|
119 lines
The following is from the November editorial. Included is source code for
EvenBetterBusError which will assemble using the MPW assembler. I've made
minor modifications for more satisfactory results (namely - changed the
string to be more specific about the nature of the problem).
Copyright © 1994 by MacTech Magazine. All rights reserved.
Feel free to use this source to build your own version, but please don't
release them under the name EvenBetterBusError. Please do include Greg Marriott
and MacTech Magazine in your credits.
-----
Unclear On The Concept
by Scott T Boyd
A reader recently sent in an excerpt from the read me for a product which shall
remain nameless:
“A common debugging tool many Mac programmers use is called EvenBetterBusError.
This tool forces a Mac to crash when certain conditions arise in order to point
out POTENTIAL problems to the programmer. The programmer can then assess the
situation and decide if there is a REAL problem which needs to be fixed. ProductX
happens to frequently create the kinds of situations which EvenBetterBusError
watches for. So, if you have EvenBetterBusError installed, you will crash
frequently with ProductX – but this is not a bug! Remove EvenBetterBusError to
eliminate the crashes. You may be asking yourself why this might concern you –
some beta releases of System Software from Apple automatically install
EvenBetterBusError when you install them. This little tool may be in your system
folder without you knowing it if you are a beta tester for Apple.”
First, a little background. EvenBetterBusError was written by Greg Marriott
while we were at Apple. Greg was responsible for checking out incompatibility
bugs between System 7 (that’s 7.0) and third-party software. He became a master
bug hunter, and nailed tons of bugs, both in our software and in third-party
software. Along the way, he developed several tools for his own detective work,
and to give to others so they could have a better chance of catching things
before they showed up in his bug list. EvenBetterBusError is a descendant of Mr.
Bus Error, which later turned into BetterBusError, and Greg took it even further.
Here’s what it does.
• It puts a 4-byte value into memory location 0. The value it puts in is
designed to generate a bus error or an illegal instruction on any Macintosh. If
someone dereferences a nil pointer, they’ll immediately generate a bus error. In
addition, they’ll crash if they jump to 0.
• It periodically checks to see whether someone has written to location 0
(probably using a NIL pointer). If so, it drops into the debugger and says,
“Write to NIL.”
Both of these behaviors can help you track down misbehaving software early, prior
to subjecting your customers to the seemingly-random system “degradation” such
bugs can induce.
Here’s some reconstituted code which shows you everything that EvenBetterBusError
does. I used TMON Pro to disassemble and save the code from the INIT resource,
then added comments and labels. As you can see, it’s pretty simple. It installs
a VBL task which periodically checks location 0, drops into the debugger if it
needs to, and stuffs $50FF8001 back into location 0.
INCLUDE 'Traps.a'
start main
BRA.S InstallVBL
BeginCodeBlock
VBLRecord
DC.L 00000000,0001 ; QElemPtr, queue type (1==VBL queue)
DC.L 00000000 ; ptr to VBL code
DC.W 0001,0000 ; timeout count & phase count
MOVE.L $0,D0 ; put location 0’s contents into D0
ANDI.L #$7FFFFFFF,D0 ; strip the high bit
CMPI.L #$50FF8001,D0 ; see if someone wrote over it
BEQ.S SkipDebugStr ; if not, everything’s ok
CMPI.L #$40810000,D0 ; see if it’s ProcMgr’s safe value
BEQ.S SkipDebugStr ; if so, everything’s ok
PEA ItsEvenBetterBusErrorsFault
_DebugStr
SkipDebugStr
MOVE.L #$50FF8001,$0 ; put a bus error value at $0
MOVE.W #$0001,$000A(A0) ; reset the VBL timer
RTS
EndOfCodeBlock
ItsEvenBetterBusErrorsFault DC.B 'Someone’s buggy software wrote to NIL',00
SizeOfCodeBlock equ EndOfCodeBlock-BeginCodeBlock
InstallVBL
MOVEQ #SizeOfCodeBlock,D0 ; allocate a block for the code & data
_NewPtr ,sys ; make a block in the system heap
MOVE.L A0,-(A7) ; remember this block's address
MOVEA.L A0,A1
LEA VBLRecord,A0 ; a static copy of our VBL record
MOVEQ #SizeOfCodeBlock,D0 ; the size of the VBL code & data
_BlockMove ; copy from INIT rsrc into system heap block
MOVEA.L (A7)+,A0 ; the system heap block
PEA $000E(A0) ; addr of ptr to VBL in VBL record
MOVE.L (A7)+,$0006(A0) ; stuff ptr to VBL code
_VInstall
MOVE.L #$50FF8001,$0 ; put a bus error value at $0
RTS
endproc
end
You might have noticed my sarcastic label on the string. Every week at Apple,
someone unclear on the concept assigned a bug to Greg that read something like,
“EvenBetterBusError caused the problem. Taking it out of the System Folder fixed
the crashes.” This common misperception puts the blame on the messenger, not the
culprit.
It’s never ok to write to location 0, nor is it ever ok to dereference
a NIL pointer. Code that does these things is buggy.
As you might imagine, the above read me file struck me (and Greg) as something of
a challenge (really more of an affront, but challenge sounded nicer). In just
starting up the software, before even getting to the EvenBetterBusError DebugStr
call, the code committed these nefarious acts: it called DisposeHandle on a PICT
resource, and called DisposeHandle on an already-disposed handle. Greg wanted me
to call them liars. I’ll go him one better. In my opinion, they’re boneheads,
the kind that give the Macintosh a bad name and get yahoos demanding memory
protection in the operating system. On the other hand, kudos to Apple for
including EvenBetterBusError in the beta versions!